<?php


class Avpt_YouTube extends WP_Widget {	

	function __construct(){
		parent::__construct('Avpt_YouTube', 'Avpt Youtube', array('description' => 'Adiciona um vídeo do youtube'));
	}

	function widget($args, $instance) {	
		include_once 'functions.php';	
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$youtube_embed_code = empty ($instance['youtube_embed_code']) ? '' : apply_filters('youtube_embed_code', $instance['youtube_embed_code']);
		$altura = empty ($instance['altura']) ? '250' : apply_filters('altura', $instance['altura']);
		$largura = empty ($instance['largura']) ? '300' : apply_filters('largura', $instance['largura']);		
		$up = empty ($instance['up']) ? '0' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '0' : apply_filters('down', $instance['down']);		
		$exploded = multiexplode(array("=" ,"&"),$youtube_embed_code);
		?>
		<div class="<?php echo 'vertical_space_'.$up?>"></div>
		<span class="pub-retranca">VÍDEO</span>
		<div>			
			<iframe width="<?php echo $largura ?>" height="<?php echo $altura ?>" src="<?php echo '//www.youtube.com/embed/'.$exploded[1] ?>" frameborder="0" allowfullscreen></iframe>
		</div>		
		<div class="<?php echo 'vertical_space_'.$down ?>"></div>
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['youtube_embed_code'] = ($new_instance['youtube_embed_code']);
		$instance['altura'] = strip_tags($new_instance['altura']);
		$instance['largura'] = strip_tags($new_instance['largura']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'youtube_embed_code' => '', 'altura' => '', 'largura' => '', 'up' => '', 'down' => ''));
		$title = strip_tags($instance['title']);
		$youtube_embed_code = $instance['youtube_embed_code'];
		$altura = strip_tags($instance['altura']);
		$largura = strip_tags($instance['largura']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('youtube_embed_code');?>"><?php _e('youtube_embed_code: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('youtube_embed_code'); ?>" name="<?php echo $this->get_field_name('youtube_embed_code'); ?>" value="<?php echo esc_attr($youtube_embed_code); ?>">
		</p>		
		<p>
		  Dimensões do vídeo<br />	
		  <label for="<?php echo $this->get_field_id('altura');?>"><?php _e('Altura em px: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('altura'); ?>" name="<?php echo $this->get_field_name('altura'); ?>" value="<?php echo esc_attr($altura); ?>">
		  <label for="<?php echo $this->get_field_id('largura');?>"><?php _e('Largura em px: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('largura'); ?>" name="<?php echo $this->get_field_name('largura'); ?>" value="<?php echo esc_attr($largura); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">
		</p>
		<p>
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px: ' ) ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}
}


class Avpt_Imagem_Principal extends WP_Widget {	

	function __construct(){
		parent::__construct('Avpt_Imagem_Principal', 'Avpt Imagem Principal', array('description' => 'Adiciona a imagem principal do site'));
	}

	function widget($args, $instance) {		
		extract($args, EXTR_SKIP);		
		$img_url = empty ($instance['img_url']) ? '' : apply_filters('img_url', $instance['img_url']);
		$img_link = empty ($instance['img_link']) ? '' : apply_filters('img_link', $instance['img_link']);
		$img_text = empty ($instance['img_text']) ? '' : apply_filters('img_text', $instance['img_text']);
		$img_text_alt = empty ($instance['img_text_alt']) ? '' : apply_filters('img_text_alt', $instance['img_text_alt']);
		$img_creditos = empty ($instance['img_creditos']) ? '' : apply_filters('img_creditos', $instance['img_creditos']);
		?>
		<style type="text/css">
		
		</style>
		<div class="vertical_space_15"></div>
		<div id="imagem-principal">
			<div class="capa">
	  			<div><a href="<?php echo $link_url ?>"><img style="margin-top:20px" src="<?php echo $img_url ?>" alt="<?php echo $img_text_alt ?>" title="<?php echo $img_text ?>" /></a></div>
			</div>
			<div style="margin-top:20px"><span class="credito cinza10"><?php echo $img_creditos ?></span></div>
		</div>
		<div class="vertical_space_15"></div>	
	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;		
		$instance['img_url'] = ($new_instance['img_url']);
		$instance['img_link'] = ($new_instance['img_link']);
		$instance['img_text'] = ($new_instance['img_text']);
		$instance['img_text_alt'] = ($new_instance['img_text_alt']);
		$instance['img_creditos'] = ($new_instance['img_creditos']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('img_url' => '', 'img_link' => '', 'img_text' => '', 'img_text_alt' => '', 'img_creditos' => ''));
		$img_url = $instance['img_url'];
		$img_link = $instance['img_link'];
		$img_text = strip_tags($instance['img_text']);
		$img_text_alt = strip_tags($instance['img_text_alt']);
		$img_creditos = strip_tags($instance['img_creditos']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('img_url');?>"><?php _e('URL da Imegem: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_url'); ?>" name="<?php echo $this->get_field_name('img_url'); ?>" value="<?php echo esc_attr($img_url); ?>">		
		  <label for="<?php echo $this->get_field_id('img_link');?>"><?php _e('Link da Imagem: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_link'); ?>" name="<?php echo $this->get_field_name('img_link'); ?>" value="<?php echo esc_attr($img_link); ?>">
		  <label for="<?php echo $this->get_field_id('img_text');?>"><?php _e('Texto da Imagem: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_text'); ?>" name="<?php echo $this->get_field_name('img_text'); ?>" value="<?php echo esc_attr($img_text); ?>">
		  <label for="<?php echo $this->get_field_id('img_text_alt');?>"><?php _e('Texto alternativo da Imagem: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_text_alt'); ?>" name="<?php echo $this->get_field_name('img_text_alt'); ?>" value="<?php echo esc_attr($img_text_alt); ?>">
		  <label for="<?php echo $this->get_field_id('img_creditos');?>"><?php _e('Créditos da Imagem: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('img_creditos'); ?>" name="<?php echo $this->get_field_name('img_creditos'); ?>" value="<?php echo esc_attr($img_creditos); ?>">
		</p>
		<?php		
	}
}



